//
//  JuListTableViewCell.swift
//  YeKa
//
//  Created by Gina on 15/10/17.
//  Copyright © 2015年 Gina. All rights reserved.
//

import UIKit
import SDWebImage

class JuListTableViewCell: UITableViewCell {

    /*
    iconView.layer.masksToBounds = true
    iconView.layer.cornerRadius = 20
    */
    
    @IBOutlet weak var eventLbl: UILabel!
    @IBOutlet weak var nowLbl: UILabel!
    @IBOutlet weak var imageBtn: UIButton!
    
    
    @IBOutlet weak var nowBtn: UIButton!
    @IBOutlet weak var titleLbl: UILabel!
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var timeLbl: UILabel!
    @IBOutlet weak var menpiaoLbl: UILabel!
    @IBOutlet weak var nameLbl: UILabel!
    @IBOutlet weak var joinNum: UILabel!
    var juInfo: JuInfo! {
        didSet {
            
            if juInfo?.type != 0 {
     
                eventLbl.text = "Event：\(juInfo!.event)"
                nowLbl.text = "Now：\(juInfo!.now)"
                if juInfo?.type == 1 {

                    
                    
                    imageBtn.setBackgroundImage(UIImage(data: NSData(contentsOfURL: NSURL(string: "http://fe.topit.me/e/50/7d/11230784712417d50eo.jpg")!)!), forState: UIControlState.Normal)
                    
                }else{
                    imageBtn.sd_setBackgroundImageWithURL(NSURL(string: "http://ic.topit.me/c/d8/fe/1123248418bdafed8co.jpg"), forState: UIControlState.Normal)
                }
                
                
            }else{
                titleLbl.text = juInfo!.theme
                nameLbl.text = juInfo!.name
                iconView.sd_setImageWithURL(NSURL(string: (juInfo!.imageUrl)!))
                
                joinNum.text = "\(juInfo!.man)人参加"
                let pp: String! = juInfo.price!
                menpiaoLbl.text = "票价：￥" + pp
            }
            
        }
    }
    
    
    
    
    class func loadCellWithTableView(tableView:UITableView, j: JuInfo) -> JuListTableViewCell {
        
        var cell: JuListTableViewCell?
        
        let ID:String?
        if j.type == 1 {
            ID = "titlecell"
        }else if j.type == 2 {
            ID = "titlecell2"
        }else{
            ID = "infocell"
        }
        
        if tableView.dequeueReusableCellWithIdentifier(ID!) == nil {
            cell = JuListTableViewCell()
        }else{
            cell = tableView.dequeueReusableCellWithIdentifier(ID!) as? JuListTableViewCell
        }
        
        cell?.juInfo = j
        return cell!
    }
    
    
    
    
}
